feat: wire ClaimsService and ClaimsController initialization - #9588
feat: wire ClaimsService and ClaimsController initialization#9588tuna1207 wants to merge 23 commits into
Conversation
Add default wallet initialization units for ClaimsService and ClaimsController with tight messenger delegation, required claimsService instance options, wallet-cli defaults, ownership, and dependency graph updates. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Colocate ClaimsService with ClaimsController so a single CODEOWNERS initializationPath covers both units, and revert multi-path ownership. Co-authored-by: Cursor <cursoragent@cursor.com>
Match the SubscriptionEnv naming pattern so wallet consumers can set claimsService.env without colliding with other Env enums. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
| storage: new InMemoryStorageAdapter(), | ||
| }, | ||
| remoteFeatureFlagController: REMOTE_FEATURE_FLAG_OPTIONS, | ||
| claimsService: { |
There was a problem hiding this comment.
Why? TransactionController doesn't interact with claims though.
There was a problem hiding this comment.
Is this really required for the test file only, since no change has been made to the corresponding controller initialization file? If not, please remove
| export type InstanceSpecificOptions = { | ||
| approvalController?: ApprovalControllerInstanceOptions; | ||
| claimsService: ClaimsServiceInstanceOptions; | ||
| claimsController?: ClaimsControllerInstanceOptions; |
There was a problem hiding this comment.
May I know why is claimsController optional but claimsService is required?
There was a problem hiding this comment.
The controller only needs state and messenger, which initialization already provides. There's nothing for the consumer to configure, so the slot is optional.
Claim Service need required fetchFunction option
|
One more thing I noticed is that shield/subscriptions/claims controllers have the different constructor interfaces. Some accept |
pedronfigueiredo
left a comment
There was a problem hiding this comment.
I see there's a bunch of comments and merge conflicts, can you address them and then re-request my review here on github once it's ready for another look?
Env is a generic infra concept, not an auth concept. Making claims/subscription/shield depend on profile-sync for a 3-value enum couples unrelated packages - every profile-sync major bump (it's at v28, moves fast) forces churn in dependents. claims/subscription currently only use it type-only; adding a runtime import makes it a real dependency. I think we can move Env into a neutral shared package - @metamask/controller-utils is the natural home since everyone already depends on it. Then profile-sync, claims, subscription, geolocation, money-account, sentinel all import from there. Each package keeps its own service URL map. |
mcmire
left a comment
There was a problem hiding this comment.
Nice work, I just have one comment.
| init: ({ messenger, options }) => | ||
| new ClaimsService({ | ||
| messenger, | ||
| env: options.env ?? Env.PRD, |
There was a problem hiding this comment.
Is this safe, do we want this to be development by default instead? I don't know what convention we've been using for other services, but it seems like we wouldn't want to hit production unnecessarily.
Alternatively should we make this option required and have clients always pass this?
There was a problem hiding this comment.
This one follow other controllers like profile sync authentication controller, money account api service all default to prd, since for all services with auth we need to follow authentication controller i think we can keep this for now and refactor all controllers to default to dev in the future if needed
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 063e097. Configure here.
|
@mcmire @pedronfigueiredo i have refactored claim service to its own separate data service and resolve all the comments, please help me review again, thank you |

Explanation
Adds
ClaimsServiceandClaimsControlleras default initialized units in the@metamask/walletpackage, following the existingInitializationConfigurationpattern used byTransactionController,StorageService, and other wallet instances.@metamask/walletis the shared controller-integration layer for extension, mobile, and other clients, so build-specific and runtime values are injected viainstanceOptionsrather than hardcoded.ClaimsService — selects the Claims API environment and platform
fetchimplementation.instanceOptions.claimsService.envandinstanceOptions.claimsService.fetchFunctionare required. The wallet init delegatesAuthenticationController:getBearerTokento the service messenger; hosts must registerAuthenticationControlleron the supplied root messenger before authenticated Claims API calls succeed.ClaimsController — stateful controller with no additional constructor options beyond optional persisted
state. The wallet init delegates only the ClaimsService actions the controller calls (fetchClaimsConfigurations,getRequestHeaders,getClaimsApiUrl,generateMessageForClaimSignature,getClaims) plusKeyringController:signPersonalMessage.Wallet release work is intentionally deferred; this PR lands the integration and documents consumer options only.
References
Per-environment options
claimsService.envEnv.DEV/Env.UAT/Env.PRD)Env.DEV/Env.UAT/Env.PRD)Env.PRDin wallet-cli;Env.DEVin wallet unit testsclaimsService.fetchFunctionfetchfetchglobalThis.fetchclaimsControllerstatestateblob when suppliedstateblob when suppliedAuthenticationController:getBearerTokenAuthenticationControlleron the wallet root messenger (not aninstanceOptionsslot)AuthenticationControlleron the wallet root messenger (not aninstanceOptionsslot)Verification
yarn workspace @metamask/wallet run testyarn workspace @metamask/wallet run jest --no-coverage src/initialization/instances/claims-service/claims-service.test.ts src/initialization/instances/claims-controller/claims-controller.test.tsyarn workspace @metamask/wallet run messenger-action-types:checkyarn workspace @metamask/wallet run lint:tsconfigsyarn workspace @metamask/wallet-cli run lint:tsconfigsyarn readme-content:checkyarn codeowners:checkyarn lint:teamsChecklist
Made with Cursor